package linkedList;

public class ReversalList {
    //给一个 单链表的头结点  返回反转链表
    public ListNode reverseList(ListNode head) {
        ListNode cur;
        ListNode temp;
        ListNode newHead = new ListNode(0);
        temp = head;
        while(temp != null){
            cur = temp.next;
            temp.next = newHead.next;
            newHead.next = temp;
            temp = cur;
        }
        return newHead.next;
    }
    public ListNode test(ListNode head){
        ListNode temp = head;
        ListNode cur;
        ListNode newHead = new ListNode(0);

        while(temp!=null){
            cur = temp.next;
            temp.next = newHead.next;
            newHead.next = temp;
            temp = cur;
        }
        return newHead.next;
    }
}
